<template>
  <div class="home">
    <!-- 导航 -->
    <van-nav-bar fixed title="智慧商城" />

    <!-- 搜索 -->
    <van-search
      background="#f1f1f2"
      placeholder="请在此输入搜索关键词"
      readonly
      shape="round"
      @click="$router.push('/search')"
    />

    <!-- 轮播 -->
    <van-swipe :autoplay="3000" class="my-swipe" indicator-color="white">
      <van-swipe-item>
        <img alt="" src="@/assets/banner1.jpg" />
      </van-swipe-item>
      <van-swipe-item>
        <img alt="" src="@/assets/banner2.jpg" />
      </van-swipe-item>
      <van-swipe-item>
        <img alt="" src="@/assets/banner3.jpg" />
      </van-swipe-item>
    </van-swipe>

    <!-- 导航 -->
    <van-grid column-num="5" icon-size="40">
      <van-grid-item
        v-for="item in navList"
        :key="item.imgUrl"
        :icon="item.imgUrl"
        :text="item.text"
        @click="$router.push('/category')"
      />
    </van-grid>

    <!-- 主会场 -->
    <div class="main">
      <img alt="" src="@/assets/main.png" />
    </div>

    <!-- 猜你喜欢 -->
    <div class="guess">
      <p class="guess-title">—— 猜你喜欢 ——</p>

      <div class="goods-list">
        <GoodsItem
          v-for="item in proList"
          :key="item.goods_id"
          :item="item"
        ></GoodsItem>
      </div>
    </div>
  </div>
</template>
<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { getHomeData } from '@/api/index'
import GoodsItem from '@/components/GoodsItem.vue'

export default {
  name: 'homeCom',
  // import引入的组件需要注入到对象中才能使用",
  components: {
    GoodsItem
  },
  data () {
    return {
      bannerList: [],
      navList: [],
      proList: []
    }
  },
  async created () {
    const {
      data: {
        data: {
          pageData: { items }
        }
      }
    } = await getHomeData()
    this.bannerList = items[1].data
    this.navList = items[3].data
    this.proList = items[6].data
  }
}
</script>

<style lang="less" scoped>
.home {
  padding-top: 40px;
  padding-bottom: 50px;
}

// 导航条样式定制
.van-nav-bar {
  z-index: 999;
  background-color: #c21401;

  ::v-deep .van-nav-bar__title {
    color: #fff;
  }
}

// 搜索框样式定制
.van-search {
  width: 100%;
  //position: fixed;
  top: 46px;
  z-index: 999;
  //border: 1px solid red;
}

// 分类导航部分
.my-swipe .van-swipe-item {
  height: 185px;
  color: #fff;
  font-size: 20px;
  text-align: center;
  background-color: #39a9ed;
}

.my-swipe .van-swipe-item img {
  width: 100%;
  height: 185px;
}

// 主会场
.main img {
  display: block;
  width: 100%;
}

// 猜你喜欢
.guess .guess-title {
  height: 40px;
  line-height: 40px;
  text-align: center;
}

// 商品样式
.goods-list {
  background-color: #f6f6f6;
}
</style>
